package com.jsmy.softapp.model;

import com.jsmy.softapp.net.API;
import com.jsmy.softapp.net.NetWork;

import java.util.Map;

import io.reactivex.disposables.CompositeDisposable;

/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/4/19.
 * Time: 11:36.
 * To change for file | settings | file and code templates.
 */

public class DataModel implements BaseModel {

    public CompositeDisposable disposable = new CompositeDisposable();

    private OnLoadCompleteListener listener = null;

    @Override
    public void loadData(String type, Map<String, String> map, OnLoadCompleteListener listener) {
        this.listener = listener;
        switch (type) {
            case API.APP_ZL_GD_LIST:
                disposable.add(NetWork.getappsyzlgdlist(API.APP_ZL_GD_LIST ,map, this));
                break;
            case API.APP_ZL_GROUP_LIST:
                disposable.add(NetWork.getappzlgrouplist(API.APP_ZL_GROUP_LIST ,map, this));
                break;
            case API.APP_SAVE_FX_INFO:
                disposable.add(NetWork.savefxinfo(API.APP_SAVE_FX_INFO, map, this));
                break;
        }
    }

    @Override
    public void onSuccess(String type, String code, String msg, Object object) {
        listener.onComplete(type, code, msg, object);
    }

    @Override
    public void onFailure(String type, String msg, String arg1) {
        listener.onComplete(type, "W", msg, null);
    }
}
